package cn.stylefeng.guns.modular.business.controller;

import cn.stylefeng.guns.modular.business.pojo.TownInfoRequest;
import cn.stylefeng.guns.modular.business.service.TownInfoService;
import cn.stylefeng.roses.kernel.rule.pojo.response.ResponseData;
import cn.stylefeng.roses.kernel.rule.pojo.response.SuccessResponseData;
import cn.stylefeng.roses.kernel.scanner.api.annotation.ApiResource;
import cn.stylefeng.roses.kernel.scanner.api.annotation.GetResource;
import cn.stylefeng.roses.kernel.scanner.api.annotation.PostResource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 城镇信息表控制器
 *
 * @author zhangyaowen
 * @date 2021/10/25 16:46
 */
@RestController
@ApiResource(name = "城镇信息表")
public class TownInfoController {

    @Resource
    private TownInfoService townInfoService;

    /**
     * 添加
     *
     * @author zhangyaowen
     * @date 2021/10/25 16:46
     */
    @PostResource(name = "添加", path = "/townInfo/add")
    public ResponseData add(@RequestBody @Validated(TownInfoRequest.add.class) TownInfoRequest townInfoRequest) {
        townInfoService.add(townInfoRequest);
        return new SuccessResponseData();
    }

    /**
     * 删除
     *
     * @author zhangyaowen
     * @date 2021/10/25 16:46
     */
    @PostResource(name = "删除", path = "/townInfo/delete")
    public ResponseData delete(@RequestBody @Validated(TownInfoRequest.delete.class) TownInfoRequest townInfoRequest) {
        townInfoService.del(townInfoRequest);
        return new SuccessResponseData();
    }

    /**
     * 编辑
     *
     * @author zhangyaowen
     * @date 2021/10/25 16:46
     */
    @PostResource(name = "编辑", path = "/townInfo/edit")
    public ResponseData edit(@RequestBody @Validated(TownInfoRequest.edit.class) TownInfoRequest townInfoRequest) {
        townInfoService.edit(townInfoRequest);
        return new SuccessResponseData();
    }

    /**
     * 查看详情
     *
     * @author zhangyaowen
     * @date 2021/10/25 16:46
     */
    @GetResource(name = "查看详情", path = "/townInfo/detail")
    public ResponseData detail(@Validated(TownInfoRequest.detail.class) TownInfoRequest townInfoRequest) {
        return new SuccessResponseData(townInfoService.detail(townInfoRequest));
    }

    /**
     * 获取列表
     *
     * @author zhangyaowen
     * @date 2021/10/25 16:46
     */
    @GetResource(name = "获取列表", path = "/townInfo/list")
    public ResponseData list(TownInfoRequest townInfoRequest) {
        return new SuccessResponseData(townInfoService.findList(townInfoRequest));
    }

    /**
     * 获取列表（带分页）
     *
     * @author zhangyaowen
     * @date 2021/10/25 16:46
     */
    @GetResource(name = "分页查询", path = "/townInfo/page")
    public ResponseData page(TownInfoRequest townInfoRequest) {
        return new SuccessResponseData(townInfoService.findPage(townInfoRequest));
    }

    @GetResource(name = "详情", path = "/townInfo/toReview")
    public ResponseData toReview(String id) {
        return new SuccessResponseData(townInfoService.toReview(id));
    }

}